import typing

# 题目：输入一个整数数组，实现一个函数来调整数组中数字的顺序，使得所有奇数位于数组的前半部分，所有偶数位于数组的后半部分
from typing import List


def reorder_odd_even(ls: List[int], func) -> (List or None):
    if not ls or len(ls) < 1:
        return None

    tmp = ls.copy()
    p_start, p_end = 0, len(ls) - 1
    # print(tmp)
    while p_start < p_end:

        while p_start < p_end and not func(tmp[p_start]):
            p_start += 1

        while p_start < p_end and func(tmp[p_end]):
            p_end -= 1

        if p_start < p_end:
            # tmp[p_start], tmp[p_end] = tmp[p_end], tmp[p_start]
            temp = tmp[p_start]
            tmp[p_start] = tmp[p_end]
            tmp[p_end] = temp
        # print(tmp)

    return tmp


def is_even(n: int):
    return n % 2 == 0


if __name__ == '__main__':
    ls = list(map(eval, list('1234567788856')))
    print(reorder_odd_even(ls, is_even))
